#include "texel_and_fonts.h"

void renderBitmapString(
                float x,
                float y,
                float z,
                void *font,
                char *string) 
{
  char *c;
  glRasterPos3f(x, y,z);
  for (c=string; *c != '\0'; c++) {
    glutBitmapCharacter(font, *c);
  }
}

void drawVariablei(Point position,char buff1[50],char buff2[50]
		   ,char* string,int valeur)
{
  /* on flush le buffer */
  memset(buff2,0,50);
  sprintf(buff2,"%d",valeur);
  /* puis on le dessine */
  drawString(position,buff1,buff2,string);
  return;
}

void drawVariabled(Point position,char buff1[50],char buff2[50]
		   ,char* string,double valeur)
{
  /* on flush le buffer */
  memset(buff2,0,50);
  sprintf(buff2,"%.1f",valeur);
  /* puis on le dessine */
  drawString(position,buff1,buff2,string);
  return;
}

/* buff 2 contient une valeur a afficher */
void drawString( Point position,char buff1[50],char buff2[50],char* string)
{
  strcpy(buff1,string);
  strcat(buff1,buff2);
  renderBitmapString(
		     position.x,position.y,position.z,
		     GLUT_BITMAP_HELVETICA_18,
		     buff1);
  return;
}



int load_secure_texel (GLuint id,char* filename)
{
/* basic flags */
  unsigned int flags=SOIL_FLAG_MIPMAPS
    | SOIL_FLAG_NTSC_SAFE_RGB
    | SOIL_FLAG_COMPRESS_TO_DXT
    | SOIL_FLAG_TEXTURE_REPEATS
    | SOIL_FLAG_INVERT_Y;



  /* load an image file directly as a new OpenGL texture */
  id = SOIL_load_OGL_texture(
				  filename,
				  SOIL_LOAD_AUTO,
				  id, /* on réutilise l'id de la texture */
				  flags
				  );

  /* check for an error during the load process */
  if( id==0 )
    {
      printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
    }
  return id;

}
/* saute n ligne, avec newLine hauteur de la ligne */
Point retourNChariot (Point p,double newLine,int n)
{
  return pt(p.x,p.y,p.z+n*newLine);
}
